using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using jQueryApi;

namespace YoshiBase.Classes
{
    // ReSharper disable UnassignedField.Global
    // ReSharper disable InconsistentNaming
    // ReSharper disable UnusedMember.Global
    // ReSharper disable NotAccessedField.Global
    // ReSharper disable FieldCanBeMadeReadOnly.Global
    [IgnoreNamespace]
    public sealed class YoshiUser
    {
        public string bio;
        public string birthday;
        public string email;
        public string first_name;
        public string gender;
        public string id;
        public string last_name;
        public string link;
        public string photo;
        public string locale;
        public string name;
        public int timezone;
        public bool hasComments;
        public string updated_time;
        public bool verified;

        public string alias;
        public string physique;
        public string height;
        public string smoker;

        public bool emmMessage = true;
        public bool emmComment = true;
        public bool emmLike = true;

        public string PhotoUrl
        {
            get { return String.IsNullOrEmpty(photo) ? "http://graph.facebook.com/" + id + "/picture?type=large" : photo; }
        }
    }

    [IgnoreNamespace]
    public abstract class YoshiAuth
    {
        public string access_token;
        public int expires;
    }

    [IgnoreNamespace]
    public sealed class YoshiAuthData
    {
        public YoshiUser User;
        public YoshiAuth Auth;
    }

    [IgnoreNamespace]
    public sealed class MagList
    {
        public string name;
        public List<string> items;
        public int create_time;
        public int modified_time;

        public MagList(string listName, jQueryObject els)
        {
            if (listName == null)
                return;
            items = new List<string>();
            name = listName;
            MagList my = this;
            if (Script.IsValue(els)) els.Each(
                delegate
                {
                    string ln = jQuery.This.GetValue().Trim();
                    if (!String.IsNullOrEmpty(ln))
                        my.items.Add(ln);
                }
            );
        }
    }

    [IgnoreNamespace]
    public sealed class PageUpdate
    {
        public bool Saved;
    }

    [IgnoreNamespace]
    public sealed class EmailListItem
    {
        public string fromId;
        public string lastId;
        public string fAlias;
        public string lAlias;
        public string peek;
        public bool unread;
        public int modifyTime;

        public EmailListItem()
        {
            modifyTime = (new Date()).GetTime();
            unread = true;
        }
    }

    [IgnoreNamespace]
    public sealed class EmailItem
    {
        public string id;
        public string alias;
        public string email;
        public string subject;
        public string message;
        public string fromId;
        public string toId;
        public int createTime;
        public int modifyTime;
        public bool unread;
    }

    [IgnoreNamespace]
    public sealed class Conversation
    {
        public string fromId;
        public string toId;
        public List<EmailItem> thread;

        //public static Conversation CollectThread(List<EmailItem> items, string id1, string id2)
        //{
        //    Conversation c = new Conversation();
        //    c.thread = new List<EmailItem>();

        //    foreach (EmailItem i in items)
        //    {
        //        if ((i.fromId == id1 && i.toId == id2) || (i.fromId == id2 && i.toId == id1))
        //        {
        //            c.thread.Add(i);
        //        }
        //    }
        //    c.thread.Sort(DateSort);
        //    return c;
        //}

        public static int DateSort(EmailItem x, EmailItem y)
        {
            return x.createTime >= y.createTime ? 1 : -1;
        }
    }
}